import { API_LIST } from '../../../Api/Api'
import { commonTableList, BuiltInData } from '../Common/common'
import { AddDataButton, ModDataButton, DelDataButton } from '../Common/options'
import { QualityProblemTypeTree } from '../Common/Conversion'

export const Quality = async ({ url, OptionsEvent, ClientData }) => {
    const parentUuid = await QualityProblemTypeTree()
    let data = {
        pageSize: 10,
        params: { pageIndex: 1 },
        hideInSearch: true,
        get: API_LIST()[`get${url}`],
        added: `pos${url}`,
        modify: `put${url}`,
        delete: `del${url}`,
        options: [
            // children.findIndex(v => v.uuid === '7139c7a2-c955-425b-944b-f0db1afa4d27') !== -1 &&
            <AddDataButton OptionsEvent={OptionsEvent} type="primary" icon="add" title="新增" />,
        ],
        columns: [
            commonTableList.uuid,
            { ...commonTableList.organizationUuid, valueEnum: ClientData.organization },
            { ...commonTableList.tableName, title: '巡检主题' },
            {
                dataIndex: 'qualityProblemTypeUuid',
                title: '安全问题类别',
                valueType: 'treeSelect',
                fieldProps: {
                    options: parentUuid,
                    fieldNames: { label: 'tableName', value: 'uuid' },
                },
                hideInTable: true,
                rules: true,
                width: 250,
            },
            {
                dataIndex: 'problem',
                title: '问题描述',
                valueType: 'input',
                rules: true,
                ellipsis: true,
                width: 250,
            },
            {
                dataIndex: 'qualityDate',
                title: '巡检日期',
                valueType: 'Date',
                showTime: true,
                rules: true,
                width: 150,
            },
            {
                dataIndex: 'limitDays',
                title: '整改天数',
                valueType: 'inputNumber',
                rules: true,
                width: 100,
            },
            {
                dataIndex: 'score',
                title: '分数',
                valueType: 'inputNumber',
                rules: true,
                width: 100,
            },
            {
                dataIndex: 'auditStatus',
                title: '状态',
                valueType: 'select',
                valueEnum: BuiltInData.PatrolStatus,
                hideInAdded: true,
                hideInModify: true,
                width: 150,
            },
            commonTableList.createUserName,
            commonTableList.createTime,
            commonTableList.updateUserName,
            commonTableList.updateTime,
            {
                title: '操作',
                valueType: 'systemOperation',
                fixed: 'right',
                width: 200,
                hideInSearch: true,
                hideInAdded: true,
                hideInModify: true,
                render: (_, record) => {
                    return [
                        <ModDataButton OptionsEvent={OptionsEvent} key="modify" title="修改" data={record} />,
                        <DelDataButton
                            OptionsEvent={OptionsEvent}
                            key="del"
                            title="删除"
                            url={url}
                            uuid={record.uuid}
                        />,
                    ]
                },
            },
        ],
    }
    return data
}
